/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package towerdefence;

import com.sun.opengl.util.FPSAnimator;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.swing.JFrame;
import net.phys2d.math.Vector2f;
import net.phys2d.raw.StaticBody;
import net.phys2d.raw.World;
import net.phys2d.raw.shapes.Line;
import net.phys2d.raw.strategies.QuadSpaceStrategyWithMouse;
import towerdefence.controller.MasterController;
import towerdefence.model.Builder;
import towerdefence.model.Model;
import towerdefence.model.Player;
import towerdefence.model.color.ColorCreator;
import towerdefence.model.color.HTMLColorCreator;
import towerdefence.model.level.TestLevel;
import towerdefence.view.GLCore;

/**
 *
 * @author Gussoh
 */
public class Main {

    private static float width = 600;
    private static float height = 400;
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        QuadSpaceStrategyWithMouse collisionStrategy = new QuadSpaceStrategyWithMouse(20, 5);
        World world = new World(new Vector2f(0, 10f), 1, collisionStrategy);
        
        Model model = new Model(new TestLevel(500, 1000), world);
        GLCore core = new GLCore(model);
                
        List<Player> players = new ArrayList<Player>();
        ColorCreator cc = new HTMLColorCreator();
        Player p = new Player(model, cc.getNextColor(), 1000000000, 10);
        Builder b = new Builder(p);
        b.setPosition(300, 450);
        players.add(p);
        
        MasterController controller = new MasterController(model, core, p, collisionStrategy);
        model.setPlayers(players);
        
        
        JFrame frame = new JFrame("Tower Defence");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.add(core);
        frame.pack();
        frame.setVisible(true);
        FPSAnimator animator = new FPSAnimator(core, 60, true);
        animator.start();
    }

    private static void addTestBodiesToWorld(Model model) {
        
//        
//        Body b = new Body(new Box(50, 50), 10);
//        b.setRestitution(0.8f);
//        b.setDamping(0.00f);
//        b.setPosition(100, 100);
//        
//        b = new Body(new Box(50, 100), 10);
//        b.setRestitution(0.8f);
//        b.setDamping(0.0f);
//        b.setPosition(100, 200);
//        model.getWorld().add(b);        
    }

    private static void addWalls(Model model) {
        Line hLine = new Line(width, 0);
        Line vLine = new Line(0, height);
        
        StaticBody leftWall = new StaticBody(vLine);
        StaticBody topWall = new StaticBody(hLine);
        StaticBody rightWall = new StaticBody(vLine);
        StaticBody bottomWall = new StaticBody(hLine);
        
        leftWall.setRestitution(0.9f);
        topWall.setRestitution(0.9f);
        bottomWall.setRestitution(0.9f);
        rightWall.setRestitution(0.9f);
        
        leftWall.setDamping(0.2f);
        topWall.setDamping(0.2f);
        bottomWall.setDamping(0.2f);
        rightWall.setDamping(0.2f);
        
        bottomWall.setPosition(0, height);
        rightWall.setPosition(width, 0);
//        model.add(leftWall);
//        model.getWorld().add(topWall);
//        model.getWorld().add(rightWall);
//        model.getWorld().add(bottomWall);
    }

}